cmake_minimum_required(VERSION 3.0)
project(esvr)

OPTION(USE_MULTI_THREAD "multithread" ON) # Enabled by default

IF(USE_MULTI_THREAD)
	ADD_DEFINITIONS(-DMULTI_THREAD)
	message("use multi thread model.")
else()
	message("use single thread model.")
ENDIF()

set(PLATFORM x86)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -ggdb -std=c++11")
set(LIB_TYPE "STATIC")
if(WIN32)
    message("now compile in win32 system")
    set(PLANTFORM_LINK "-lwsock32")
elseif(APPLE)
    set(PLANTFORM_LINK "")
    message("now compile in macos system")
elseif(UNIX)
    set(PLANTFORM_LINK "-pthread")
    message("now compile in unix system")
endif()

add_subdirectory(3rd)
include_directories(3rd/lua-5.3.2/src)

set(SOURCE_FILES main.cpp)
add_executable(esvr ${SOURCE_FILES} es_socket.h es_socket.cpp es_log.h es_util.h es.h es.cpp)
target_link_libraries(esvr ${PLANTFORM_LINK} lua)

add_executable(test_cata test/test_cata.cpp)
add_executable(test_thread_pool test/test_thread_pool.cpp)
target_link_libraries(test_thread_pool ${PLANTFORM_LINK})

set(TEST_LUA_HTTP_SOURCE test/test_lua_http_server.cpp)
add_executable(test_lua_http_server ${TEST_LUA_HTTP_SOURCE} es_socket.h es_socket.cpp es_log.h es_util.h es.h es.cpp)
target_link_libraries(test_lua_http_server ${PLANTFORM_LINK} lua)

set(TEST_LUA_JSON_SOURCE test/test_lua_json_server.cpp)
add_executable(test_lua_json_server ${TEST_LUA_JSON_SOURCE} es_socket.h es_socket.cpp es_log.h es_util.h es.h es.cpp)
target_link_libraries(test_lua_json_server ${PLANTFORM_LINK} lua)
